package com.lx.chong.service.impl;

import com.lx.chong.dto.PageAndSortDto;
import com.lx.chong.model.Department;
import com.lx.chong.repository.DepartmentRepository;
import com.lx.chong.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chong
 * @create 2019/5/15
 * Desc:
 */
@Service
public class DepartmentServiceImpl extends BaseServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentRepository departmentRepository;

    @Override
    public List<Department> findAllByIfDeleteAndUseMark() {
        return departmentRepository.findAllByIfDeleteAndUseMark(0,1);
    }

    @Override
    public Department findOne(Long id) {
        return departmentRepository.findOne(id);
    }

    @Override
    public Department save(Department department) {
        return departmentRepository.save(department);
    }

    @Override
    public List<Department> getDepListPage(Integer page, Integer size) {
        return departmentRepository.getDepListPage(page*size,size);
    }

    @Override
    public Long getDepCount() {
        return departmentRepository.getDepCount();
    }

    @Override
    public Page<Department> getDepListPage(PageAndSortDto dto) {
        return getPageAndSortThis(dto,departmentRepository);
    }
}
